<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .myClass{
        background-color: green;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <basic-input 
        label="用户名" 
        v-bind:val="username" 
        @input2="handleInput"
      ></basic-input>
      <p>{{username}}</p>
    </div>
    <script src="vue.js"></script>
    <script src="vue-router.js"></script>
    <script>
      Vue.component('basic-input',{
        //inheritAttrs:false,
        //通过声明props,接收父组件传递过来的label和value值
        props:['id','label','val'],
        template:`
        <label>
          <p>{{label}}</p>
          <input
            v-bind:value="val"
            v-on:input="$emit('input2',$event.target.value)"
          />
        </label>
        `,
        created(){
          console.log('$listeners',this.$listeners)
        }
      });
      var vm = new Vue({
        el:'#app',
        data:()=>({
          username:''
        }),
        methods:{
          handleInput(newVal){
            this.username = newVal;
          }
        }
      });
    </script>
  </body>
</html>
